package com.msite.web

import org.springframework.stereotype.Controller
/*import net.sf.jasperreports.engine.JRParameter
import net.sf.jasperreports.engine.JasperRunManager
import net.sf.jasperreports.engine.data.JRXmlDataSource
import net.sf.jasperreports.engine.query.JRXPathQueryExecuterFactory*/
/**
 * Created by tpeng on 2015/12/31.
 */
@Controller
public class TestController {

    /*@Resource
    private RabbitmqService rabbitmqService;

    @RequestMapping(value = "/test/rmq")
    @ResponseBody
    public Object rmq(Model model){
        rabbitmqService.sendMessage();
        JsonResult json = new JsonResult();
        json.setCode(200);
        json.setMsg("ok");
        return json;
    }

    @RequestMapping(value = "/test/rmq1")
    @ResponseBody
    public Object rmq1(Model model){
        rabbitmqService.sendContentMessage();
        JsonResult json = new JsonResult();
        json.setCode(200);
        json.setMsg("ok");
        return json;
    }*/

    /*@RequestMapping(value = "/test/xmlToPdf")
    void xmlToPdf(HttpServletResponse response){
        def reportFile = new File("/home/report2.jasper") // new File("D:\\C11\\report2.jasper")
        Map parameters = new HashMap();
//        parameters.put("name", "p");
        def xml = new File("/home/CES-A330_01.xml") //new File("D:\\C11\\CES-A330_01.xml")
//        println FileCopyUtils.copyToString(new FileReader(xml))
//        Document document = JRXmlUtils.parse(JRLoader.getLocationInputStream(xml.path));
//        parameters.put(JRXPathQueryExecuterFactory.PARAMETER_XML_DATA_DOCUMENT, document);
//        parameters.put(JRXPathQueryExecuterFactory.XML_DATE_PATTERN, "yyyy-MM-dd");
//        parameters.put(JRXPathQueryExecuterFactory.XML_NUMBER_PATTERN, "#,##0.##");
        parameters.put(JRXPathQueryExecuterFactory.XML_LOCALE, Locale.CHINESE);
        parameters.put(JRParameter.REPORT_LOCALE, Locale.CHINA);

        byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, new JRXmlDataSource(xml));

        response.setContentType("application/pdf");
        response.setContentLength(bytes.length);
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition", "inline; filename=\"" //attachment
                + URLEncoder.encode("测试生成pdf", "UTF-8")+ ".pdf\"");
        ServletOutputStream ouputStream = response.getOutputStream();
        ouputStream.write(bytes, 0, bytes.length);
        ouputStream.flush();
        ouputStream.close();
    }*/
}
